package com.scedu.reflection;

import java.lang.annotation.*;
import java.lang.reflect.Field;

//练习反射操作注解

public class Test11 {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchFieldException {
        Class c1 = Class.forName("com.scedu.reflection.Student2"); //反射
        //通过反射获得注解
        Annotation[] annotations = c1.getAnnotations();
        for (Annotation annotation : annotations) {
            System.out.println(annotation);
        }
        //获取注解的value的值
        Annotation annotation = c1.getAnnotation(TableName.class);
        TableName tableName=(TableName) annotation;// 强制类型转换
        System.out.println(tableName.value());

        //获取类指定的注解
        Field fname = c1.getDeclaredField("name");
        Annotation annotation1 = fname.getAnnotation(fieldAnnotation.class);
        fieldAnnotation fieldAnnotation=(fieldAnnotation) annotation1;
        System.out.println(annotation1);
        System.out.println(fieldAnnotation.columnName());
    }
}


